home *** CD-ROM | disk | FTP | other *** search
Wrap
#!/bin/bash # This provides a stripped down 'failsafe' mode for situations # where X is failing to start up. # Author: Bryce W. Harrington <bryce@canonical.com> # Copyright 2007, 2008 Canonical, Ltd # # This is free software; you may redistribute it and/or modify # it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2, # or (at your option) any later version. # # This is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License with # the Debian operating system, in /usr/share/common-licenses/GPL; if # not, write to the Free Software Foundation, Inc., 59 Temple Place, # Suite 330, Boston, MA 02111-1307 USA xorg_conf=$1 with_gdm=$2 display=0 xorg_log="/var/log/Xorg.${display}.log" gdm_log="/var/log/gdm/:${display}.log" apport_hook="/usr/share/apport/xserver_hook" app_width=300 app_height=300 app_title="Ubuntu Failsafe-X" timestamp=$(date +%y%m%d%H%M%S) display_main_menu() { zenity --list \ --radiolist \ --title "$app_title" \ --width $app_width --height $app_height \ --text "What would you like to do?" \ --column "" --column "Choice" --column "" \ TRUE LOW_RES_MODE "Run Ubuntu in low-graphics mode for just this session" \ FALSE RECONFIGURE "Reconfigure graphics" \ FALSE TROUBLESHOOT "Troubleshoot the error" \ --hide-column 2 # TODO: 3 FILE_BUG "Report a bug about this failure" \ } display_reconfigure_menu() { # TODO: Only display SELECT_BACKUP if backups are available zenity --list \ --radiolist \ --title "$app_title : Reconfiguration" \ --text "How would you like to reconfigure your display?" \ --width $app_width --height $app_height \ --column "" --column "Choice" --column "" \ TRUE RUN_DEXCONF "Use default (generic) configuration" \ FALSE RUN_XORGCONF "Create new configuration for this hardware" \ FALSE SELECT_BACKUP "Use your backed-up configuration" \ --hide-column 2 } display_troubleshooting_menu() { zenity --list \ --radiolist \ --title "$app_title : Troubleshooting" \ --text "What information would you like to review?" \ --width $app_width --height $app_height \ --column "" --column "Choice" --column "" \ TRUE VIEW_XORG_LOG "Review the xserver log file" \ FALSE VIEW_GDM_LOG "Review the startup errors" \ FALSE EDIT_CONFIG "Edit configuration file" \ FALSE SAVE_CONFIG_LOGS "Archive configuration and logs" \ --hide-column 2 # TODO: 5 VERIFY_XORGCONF "Check configuration file" # TODO: 6 EXIT_TO_CONSOLE "Exit to console" \ } # TODO: Should we just go ahead and file a bug for them without presenting an option? display_filebug_menu() { # Run apport to file a bug if [ -e $apport_hook ]; then $apport_hook if [ $? == 0]; then zenity --info --text "A bug report has been written.\nYou can send it next time you log in." else zenity --error --text "Your bug could not be recorded successfully.\n" fi else zenity --error --text "Cannot file bug: $apport_hook is not present." fi } backup_xorg_conf() { # TODO: backup xorg.conf more elegantly... xorg_conf_backup="/etc/X11/xorg.conf-backup-${timestamp}" cp /etc/X11/xorg_conf ${xorg_conf_backup} if [ ! $? ]; then return zenity --question --text "Your config could not be backed up.\nDo you want to continue anyway?\n" fi } run_dexconf() { backup_xorg_conf || return 1 dexconf if [ $? == 0 ]; then zenity --info --text "Your configuration has been restored to default,\nand your old configuration backed up.\nPlease restart.\n" else # TODO: Copy $xorg_conf_backup to $xorg_conf if it exists zenity --error --text "Failure restoring configuration to default.\nYour config has not been changed." fi } run_xorgconf() { backup_xorg_conf || return 1 Xorg :99 -configure if [ $? == 0 ]; then zenity --info --text "A new configuration has been generated,\nand your old configuration backed up.\nPlease restart.\n" else zenity --error --text "Could not generate a new configuration" fi } view_xorg_log() { gedit $xorg_log } view_gdm_log() { gedit $gdm_log } verify_xorgconf() { # Run Alberto's xorg.conf checker (once it's available in main) zenity --error --text "Sorry, this option is not implemented yet" } edit_config() { backup_xorg_conf || return 1 gksu gedit "/etc/X11/xorg.conf" } save_config_logs() { xorg_backup_name=failsafeX-backup-${timestamp} xorg_backup_dir=$(mktemp -d -t ${xorg_backup_name}.XXX) xorg_backup_file=/var/log/${xorg_backup_name}.tar # cp $xorg_conf $xorg_backup_dir cp /etc/X11/xorg.conf $xorg_backup_dir cp $xorg_log $xorg_backup_dir cp $gdm_log $xorg_backup_dir tar -cf $xorg_backup_file $xorg_backup_dir rm -rf $xorg_backup_dir zenity --info --text "Relevant configuration and log files have been saved to:\n$xorg_backup_file\nBug reports can be submitted at http://www.launchpad.net/ubuntu/.\n" } # Scan Xorg.0.log for errors LOG_ERRORS=$(grep -e "^(EE)" $xorg_log) if [ -z "$LOG_ERRORS" ]; then zenity --warning --text "<big><b>Ubuntu is running in low-graphics mode</b></big>\n\nYour screen, graphics card, and input device settings\ncould not be detected correctly. You will need to configure these yourself." else zenity --warning --text "<big><b>Ubuntu is running in low-graphics mode</b></big>\n\nThe following error was encountered. You may need\nto update your configuration to solve this.\n\n${LOG_ERRORS}" fi # TODO: Add --window-icon "$app_icon" to all zenity windows while : ; do case "$choice" in ## Main Menu ## LOW_RES_MODE ) with_gdm="low-res"; break ;; RECONFIGURE ) choice=$(display_reconfigure_menu) ;; TROUBLESHOOT ) choice=$(display_troubleshooting_menu) ;; FILE_BUG ) choice=$(display_filebug_menu) ;; ## Reconfigure Menu ## RUN_DEXCONF ) choice="RECONFIGURE"; run_dexconf ;; RUN_XORGCONF ) choice="RECONFIGURE"; run_xorgconf ;; SELECT_BACKUP ) choice="RECONFIGURE"; ;; ## Troubleshooting Menu ## VIEW_XORG_LOG ) choice="TROUBLESHOOT"; view_xorg_log ;; VIEW_GDM_LOG ) choice="TROUBLESHOOT"; view_gdm_log ;; VERIFY_XORGCONF ) choice="TROUBLESHOOT"; verify_xorgconf ;; EDIT_CONFIG ) choice="TROUBLESHOOT"; edit_config ;; SAVE_CONFIG_LOGS ) choice="TROUBLESHOOT"; save_config_logs ;; EXIT_TO_CONSOLE ) with_gdm=""; break ;; EXIT ) break ;; *) choice=$(display_main_menu) || break ;; esac done zenity --info --text "Stand by one minute while the display restarts..." if [ "x$with_gdm" = "xwith-gdm" ]; then export XORGCONFIG="/etc/X11/xorg.conf" /etc/init.d/gdm restart elif [ "x$with_gdm" = "xlow-res" ]; then export XORGCONFIG=${xorg_conf} /etc/init.d/gdm restart fi